import { Component, Input, OnInit } from '@angular/core';
import { IConfig } from '@onlyoffice/document-editor-angular';


@Component({
    selector: 'app-onlyoffice',
    templateUrl: 'component.html',
    styleUrls: ['component.scss']
})
export class OnlyofficeComponent implements OnInit{
    @Input() url = 'http://maxiao.fun:3011/web/document/documentDownload?documentId=2';
    @Input() title = 'test';
    @Input() fileType = 'pdf';
    @Input() fileId = 'Khirz6zTPdfd7d';
    @Input() show = false;
    config: IConfig = {
        document: {
            fileType: this.fileType,
            key: this.fileId,
            title: this.title,
            url: this.url,
            permissions: {edit: false},
        },
        editorConfig: {
            mode: 'view',
            user: {
                id: 'uid-1',
                name: 'John Smith',
            },
            callbackUrl: 'http://maxiao.fun:1080/url-to-callback.ashx'
        },
        height: '100%',
        width: '100%',
        type: 'embedded', //mobile,desktop,embedded
    };

    onDocumentReady = (event) => {
    }

    onLoadComponentError = (errorCode, errorDescription) => {
        switch (errorCode) {
            case -1: // Unknown error loading component
                break;

            case -2: // Error load DocsAPI from http://documentserver/
                break;

            case -3: // DocsAPI is not defined
                break;
        }
    }

    ngOnInit(): void {
        this.config.document.url = this.url;
        this.config.document.title = this.title;
        this.config.document.key = this.fileId;
        this.config.document.fileType = this.fileType;
        setTimeout(() => {
            this.show = true;
        }, 1000);
    }
}
